/*BEGIN: jQuery Function*/
/*vTip*/
this.vtip = function() {    
    this.xOffset = -10;
    this.yOffset = 20;
    $(".vtip").unbind().hover(    
        function(e) {
            this.t = this.title;
            this.title = ''; 
            this.top = (e.pageY + yOffset); this.left = (e.pageX + xOffset);
            $('body').append( '<p id="vtip"><img id="vtipArrow" />' + this.t + '</p>' );       
            $('p#vtip #vtipArrow').attr("src", 'http://thitruong24gio.com/templates/shop/' + $('.header').attr('styleshop') + '/images/vtipArrow.png');
            $('p#vtip').css("top", this.top+"px").css("left", this.left+"px").fadeIn("medium");
        },
        function() {
            this.title = this.t;
            $("p#vtip").fadeOut("medium").remove();
        }
    ).mousemove(
        function(e) {
            this.top = (e.pageY + yOffset);
            this.left = (e.pageX + xOffset);      
            $("p#vtip").css("top", this.top+"px").css("left", this.left+"px");
        }
    );            
};
jQuery(document).ready(function($){vtip();});
/*Vote*/
$(document).ready(function(){
	var img1 = $('#vote1').attr('src');
	var img2 = $('#vote2').attr('src');
	var img3 = $('#vote3').attr('src');
	var img4 = $('#vote4').attr('src');
	var img5 = $('#vote5').attr('src');
	var srcImg = 'http://thitruong24gio.com/templates/shop/' + $('.header').attr('styleshop') + '/images/';
	$('.vote').hover(function(){
		for(var i = 1; i <= Math.min($(this).attr('alt'), 5); i++)
		{
			$('#vote' + i).attr('src', srcImg + 'starYellow1.gif');
		}
		for(i = Math.min($(this).attr('alt'), 5) + 1; i <= 5; i++)
		{
			$('#vote' + i).attr('src', srcImg + 'starYellow0.gif');
		}
	},
	function(){
		$('#vote1').attr('src', img1);
		$('#vote2').attr('src', img2);
		$('#vote3').attr('src', img3);
		$('#vote4').attr('src', img4);
		$('#vote5').attr('src', img5);
	});
});
/*Light Box*/
(function($){
	$.fn.lightBox = function(id, fade){
		if(fade == true)
		{
			$('#' + id).fadeIn('medium');
		}
		else
		{
			$('#' + id).css('display', 'block');
		}
	}
})(jQuery);
(function($){
	$.fn.middlePosition = function(id, height){
		if(height == 0)
		{
			$('#' + id).css('margin-top', ($(window).height() - $('#' + id).height())/2);
		}
		else
		{
			$('#' + id).css('margin-top', ($(window).height() - height)/2);
		}
	}
})(jQuery);
(function($){
	$.fn.messageGlobal = function(message, fade){
		$('#messageGlobal').html(message);
		$().lightBox('messageGlobalContainer', fade);
	}
})(jQuery);
$(document).ready(function(){
	$('.callMessage').click(function(){
		$('#messageGlobal').html($(this).attr('message'));
		$().lightBox('messageGlobalContainer', true);
	});
	$('.closeLightBox').click(function(){
		$('.container').fadeOut('medium');
	});
	setInterval("$().middlePosition('messageGlobalLightBox', 0)", 5);
});
/*Search*/
(function($){
	$.fn.filterUrl = function(url){
		for(var i = 0; i < url.length; i++)
		{
			url = url.replace('/', ' ');
			url = url.replace('%', ' ');
			url = url.replace('#', ' ');
		}
		return jQuery.trim(url);
	};
})(jQuery);
$(document).ready(function(){
	$('#buttonSearch').click(function(){
		if($().filterUrl($('#txtSearch').val()) != '')
		{
			redirect('http://thitruong24gio.com/' + $('.header').attr('nameshop') + '/product/search/name/' + $().filterUrl($('#txtSearch').val()));
		}
	});
});
/*Go Top*/
(function($){
	$.fn.goTop = function(id){
		$('html, body').animate({scrollTop:$('#' + id).offset().top}, 'slow');
	}
})(jQuery);
$(document).ready(function(){
	$('.goTop').click(function(){
		$().goTop('top');
	});
});
/*Back*/
$(document).ready(function(){
	$('.bBack').click(function(){
		history.go(-1);
	});
});
/*Fix PNG IE6*/
$(document).ready(function(){
	if(jQuery.browser.msie && jQuery.browser.version.substr(0,2) == '6.')
	{
		$(document).pngFix();
	}
});
/*END jQuery Function*/
/*BEGIN: My Function*/
/*Redirect*/
function redirect(url)
{
	document.location.href = url;
}
/*Proc*/
function proc(action, val)
{
	document.frmProc.action.value = action;
	document.frmProc.val.value = val;
	document.frmProc.submit();
}
/*Bookmark*/
function bookmark(url, title)
{
	if((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4))
	{
		window.external.AddFavorite(url, title);
	}
	else
	{
		if(navigator.appName == "Netscape")
		{
			window.sidebar.addPanel(title, url, "");
		}
		else
		{
			alert("Press CTRL-T (Netscape) or CTRL-D (Opera) to bookmark");
		}
	}
}
/*END My Function*/